package com.springboot.admin.service.impl;

import com.springboot.admin.common.ResponseMap;
import com.springboot.admin.entity.CateDto;
import com.springboot.admin.entity.NavigationDto;
import com.springboot.admin.mapper.NavigationDao;
import com.springboot.admin.service.NavigationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class NavigationServiceImpl implements NavigationService {

  @Autowired
  NavigationDao navigationDao;

  public List<Map> getAll() {
    List<Map> cateList = navigationDao.getCate();
    for (Map cate: cateList){
      cate.put("children", navigationDao.getListByCate(cate.get("id").toString()));
    }
    return cateList;
  }

  public NavigationDto getDetail(int  id) {
    return navigationDao.getDetail(id);
  }

  public ResponseMap insertOne(NavigationDto navigationDto) {
    navigationDao.insertOne(navigationDto);
    return ResponseMap.success("新增成功");
  }

  public void delOne(int id) {
    navigationDao.delOne(id);
  }

  public void updateOne(NavigationDto navigationDto) {
    navigationDao.updateOne(navigationDto);
  }

  public List getCate() {
    return navigationDao.getCate();
  }

  public void insertCate(CateDto cateDto) {
    navigationDao.insertCate(cateDto);
  }

  public void updateCate(CateDto cateDto) {
    navigationDao.updateCate(cateDto);
  }

  public void delCate(int id) {
    navigationDao.delCate(id);
  }
}
